define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Activity_info, $ionicSlideBoxDelegate, $stateParams,GoPage,$sce,GoDialog) {
		
		$scope.selectTab = 0;
		
		//页面激活
		$scope.$on('$ionicView.afterEnter', function() {
			$scope.goods_id = $stateParams.goods_id;
			$scope.product_id = $stateParams.product_id;
			$scope.act_id = $stateParams.act_id;
			GoPage.init_top($scope, 44, 0);
			$scope.init_data(); //必须在定义之后
		}, false);
		
		$scope.activeTab = function(index) {
			$scope.selectTab = index;
			$ionicSlideBoxDelegate.$getByHandle('tab-handle').slide(index);
		};
		//滑动切换
		$scope.slideChanged = function(index) {
			$scope.selectTab = index;
		};
		
		//禁止左右滑动来切换页面1
		$scope.onTouch = function() {
			$ionicSlideBoxDelegate.$getByHandle('tab-handle').enableSlide(false);
		};
		//禁止左右滑动来切换页面2
		$scope.onRelease = function() {
			$ionicSlideBoxDelegate.$getByHandle('tab-handle').enableSlide(true);
		};
		
		/*
		 * 9个活动
		 * 活动类型
			1=>团购活动
			2=>秒杀活动
			3=>限时抢购活动
			4=>拍卖活动
			5=>新品测试活动
			6=>新品赠送活动
			7=>新品公告活动
			8=>产品推广活动(直播)
			9=>产品促销活动
		*/
		function getMethod(){
			if($stateParams.type=='1') {//
				$scope.title = "疯狂团购";
				$scope.method = "goods.groupbuy.rule";
			}
			if($stateParams.type=='2') {
				$scope.title = "限时秒杀";
				$scope.method = "goods.seckill.rule";
			}
			if($stateParams.type=='3') {
				$scope.title = "限时抢购";
				$scope.method = "goods.panicbuy.rule";
			}
			if($stateParams.type=='4') {
				$scope.title = "限时拍卖";
				$scope.method = "marketing.auction.description";
			}
			if($stateParams.type=='5') {
				$scope.title = "新品测试";
				$scope.method = "goods.test.descriptionandrule";
			}
			if($stateParams.type=='6') {
				$scope.title = "新品赠送";
				$scope.method = "marketing.giving.rule";
			}
			if($stateParams.type=='7') {
				$scope.title = "新品公告";
				$scope.method = "marketing.notice.rule";
			}
		}
		
		//初始化
		$scope.init_data = function() {
			getMethod();
			Activity_info.get_description($scope.goods_id,$scope.act_id,$scope.product_id, $scope.method, function(data) {
//			    console.log(data)
			    if(!data.success){
			    	GoDialog.alert("提示",data.msg);
					return;
			    }
//				$scope.rule = $sce.trustAsHtml(data.result.rule);
				$scope.data = data.result;
				$scope.description = $sce.trustAsHtml(data.result.description);
			})
		};
		

	}

	controller.$inject = ['$scope', 'Activity_info', '$ionicSlideBoxDelegate', '$stateParams','GoPage','$sce','GoDialog'];

	return app.registerController("activity_infoctrl",controller);
});